// 主页的js
// $.ajax({
//   url: '/my/user/userinfo',
//   success: function (res) {
//     console.log(res)
//   }
// })

//---------------------------------------
function getUserInfo() {
  $.ajax({
    url: '/my/user/userinfo',
    success: function (res) {
      console.log(res)
      if (res.status === 0) {
        let name = res.data.nickname || res.data.username
        $('.username').text(name)
        if (res.data.user_pic) {
          // let pic = res.data.user_pic
          $('.layui-nav-img').attr('src', res.data.user_pic).show()
        } else {
          let first = res.data.username.substring(0, 1).toUpperCase()
          $('.text-avatar').text(first).css('display', 'inline-block')
        }
      }
    },
  })
}
getUserInfo()


//------------------------点击退出----------------- 
$('#togout').on('click', function () {
  layer.confirm('你确定退出吗？', function (index) {
    localStorage.removeItem('token')
    location.href = './login.html'
    layer.close(index)
  })
})